//
//  HJGroupListCell.m
//  KaiChat
//
//  Created by lx on 2023/11/2.
//

#import "HJGroupListCell.h"

@interface HJGroupListCell()

@property (nonatomic, weak) UIImageView *avatarImageView;
@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) UILabel *introduceLabel;
@property (nonatomic, weak) UILabel *memberCountLabel;

@end


@implementation HJGroupListCell

 
- (void)settingSubView {
    [super settingSubView];
    
    UIImageView *avatarImageView = [UIImageView addToView:self.contentView];
    avatarImageView.addCornerRadius(23);
    avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
    [avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(leftRightMargin);
        make.centerY.offset(0);
        make.width.height.offset(46);
    }];
    
    UILabel *nameLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(avatarImageView.mas_right).offset(10);
        make.top.equalTo(avatarImageView).offset(4);
        make.right.mas_lessThanOrEqualTo(-86);
    }];
 
    UILabel *memberCountLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(12) color:UIColor.tj_BEBDCAColor title:nil textAlignment:NSTextAlignmentLeft];
    [memberCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(nameLabel);
        make.right.inset(leftRightMargin);
    }];
    
    UILabel *introduceLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(12) color:UIColor.tj_868391Color title:nil textAlignment:NSTextAlignmentLeft];
    [introduceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(avatarImageView.mas_right).offset(10);
        make.bottom.equalTo(avatarImageView).inset(3);
        make.right.mas_lessThanOrEqualTo(-20);
    }];
    
    _avatarImageView = avatarImageView;
    _nameLabel = nameLabel;
    _introduceLabel = introduceLabel;
    _memberCountLabel = memberCountLabel;
}
 
- (void)setModel:(HJChatGroupModel *)model {
    _model = model;
        
    
    if (model.searchAttributedString) {
        _nameLabel.attributedText =  model.searchAttributedString;
    } else {
        _nameLabel.attributedText = nil;
        _nameLabel.text = model.name;
    }
    

    if (model.intro.length) {
        _introduceLabel.text = model.intro;
    } else {
        _introduceLabel.text = groupDefaultIntroduce;
    }
    
    if (isEmptyString(model.avatar)) {
        _avatarImageView.image = [UIImage imageNamed:defaultAvatarName];
    } else {
        [_avatarImageView sd_setImageWithURL:model.avatar.URL placeholderImage:[UIImage imageNamed:defaultAvatarName]];
    }
    
    if (model.role.intValue == 1) {
        _memberCountLabel.text = [NSString stringWithFormat:@"(%@ people)", model.memberNums];
    } else {
        _memberCountLabel.text = nil;
    }
    
}
 

@end


